﻿// Copyright (c)  YISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using JetBrains.Annotations;
using NSQL.Sharpen;

namespace NSQL.Expressions.Functions
{
    public class SubStringFunction : BaseExpression, ISubStringFunction
    {
        public IStringExpression Text { get; set; }
        public IIntegerExpression Position { get; set; }
        public IIntegerExpression Length { get; set; }

        public SubStringFunction(IExpression text, IIntegerExpression position, IIntegerExpression length = null)
        {
            Text = (IStringExpression) text;
            Position = position;
            Length = length;
        }
        
        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
        public override void Accept(IExpressionVisitor visitor) => visitor.Visit(this);
        public override bool IsValid => Text.IsValid && Position.IsValid && Length.IsValid;
        protected override IExpression DeepCopy()
        {
            return new SubStringFunction(Text.DeepClone(), Position.DeepClone(), Length.DeepClone())
            {
                Tag = Tag
            };
        }
    }
}